package org.argeproje.resim.proc;

import java.awt.image.renderable.ParameterBlock;


import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;

import org.argeproje.resim.proc.data.Data;
import org.argeproje.resim.proc.data.ImageDA;

public class BandSelectPR extends Processor {
    int _bandIndex = 0;
	public void setParameters(int bandIndex){
    	setParamBandIndex(bandIndex);
    }
	public void setParamBandIndex(int bandIndex){
		_bandIndex = bandIndex;
	}
	public int getParamBandIndex(){
		return _bandIndex;
	}
	public Data process() {
		PlanarImage i = getInputAsPlanarImage();
		int nBand = getInputAsImageDA().getNBands();
		int bandIndex = getParamBandIndex();
		if(bandIndex >= nBand){
			setParamBandIndex(bandIndex - 1);
		}
		int[] indices = new int[1];
		indices[0] = getParamBandIndex();
		ParameterBlock pb = new ParameterBlock();
		pb.addSource(i);
		pb.add(indices);
		PlanarImage o = JAI.create("bandselect", pb);
		ImageDA out = new ImageDA(o);
		setOutput(out);
		return getOutput();
	}

}
